<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			"use strict"
			var xmlFileName = "readXML.xml";
			var xmlDoc = "";
			if(window.ActiveXObject){ // IE
				console.log("IE");
				var activeXNameList = new Array("MSXML2.DOMDocument.6.0",
				"MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",
				"MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument",
				"Microsoft.XMLDOM", "MSXML.DOMDocument");
				for(var index = 0; index < activeXNameList.length; index++){
					console.log(activeXNameList[index]);
					try{
						xmlDoc = new ActiveXObject(activeXNameList[index]);
					}catch(e){
						
						continue;
					}
					if(xmlDoc){
						
						break;
					}
				}
			}else if(document.implementation && document.implementation.createDocument){ // 非IE
				console.log("非IE");
				xmlDoc = document.implementation.createDocument("","",null);
			}else {
				alert('can not create XML DOM object, update your browser please...');
			}
			xmlDoc.async = false; //是否异步 属性false 表 同步;
									//防止后面程序处理时文件还没加载完导致出现错误,
			console.log("xmlDoc=" + xmlDoc + "\n" + xmlDoc.nodeName);
			console.log(xmlDoc.load);//结果为:IE9,10,11 和 Chrome undefined
			
			if(xmlDoc.load){
				xmlDoc.load(xmlFileName);//加载XML //火狐可以实现(未测) 
			}else{
				console.log("使用new XMLHttpRequest()");
				var xmlhttp = new window.XMLHttpRequest();
				xmlhttp.open("get",xmlFileName,false);
				xmlhttp.send(null);
				xmlDoc = xmlhttp.responseXML;
				console.log(xmlDoc)
			}
			//Chrome 没有.load()函数
			
			//JS读取 XML 文件中的 area 节点的方式如下:
			if(window.ActiveXObject){
				var nodeList = xmlDoc.documentElement.getElementsByTagName("area");// IE
				for(var i = 0;i<nodeList.length;i++){
					//遍历操作
					var attributeValue = nodeList[i].getAttribute("areaid");
					debug("IE浏览器效果：" + attributeValue);
				}
			}else{
				var nodeList = xmlDoc.getElementsByTagName("area");// 非IE 
				for(var i = 0;i<nodeList.length;i++){
					//遍历操作
					var attributeValue = nodeList[i].getAttribute("areaid");
					debug("非IE浏览器效果：" + attributeValue);
				}
			}
			
			
			
		</script>
	</body>
</html>
